package com.miguo.framework.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.miguo.framework.R;

/**
 * ToastUtils
 */
public class Toast {

    /**
     * 短暂显示Toast消息
     *
     * @param message
     */
    public static void show(Context context, String message) {
        showCenterToast(context, message, false);
    }

    public static void show(Context context, String message, boolean warnIcon) {
        showCenterToast(context, message, warnIcon);
    }

    private static void showCenterToast(Context context, String message,
                                        boolean warnIcon) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.custom_toast, null);
        if (warnIcon) {
            ImageView mWarn = (ImageView) view.findViewById(R.id.toast_warn_icon);
            mWarn.setVisibility(View.VISIBLE);
        }
        TextView text = (TextView) view.findViewById(R.id.toast_message);
        text.setText(message);
        android.widget.Toast toast = new android.widget.Toast(context);
        toast.setDuration(android.widget.Toast.LENGTH_SHORT);
        int yOff = (int) (70 * context.getResources().getDisplayMetrics().density + 0.5f);
        toast.setGravity(Gravity.BOTTOM, 0, yOff);
        toast.setView(view);
        toast.show();
    }

}